package com.woniuxy.light_smart.controller;



import com.woniuxy.light_smart.entity.Role;
import com.woniuxy.light_smart.entity.UserRole;
import com.woniuxy.light_smart.service.RoleService;
import com.woniuxy.light_smart.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("role")
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("{id}")
    public Result selectRidByuid(@PathVariable("id") Long id) {
        List<Integer> integers = roleService.selectRidByUid(id);
        List<UserRole> userRoles = roleService.selectAllRole();
        return Result.ok().data("checked", integers).data("roleList", userRoles);

    }

    @GetMapping("")
    public Result sell() {
        List<Role> roleList = roleService.selectAll();
        if (roleList != null) {
            return Result.ok().data("list", roleList);
        } else {
            return Result.error();
        }
    }
}